import 'package:erp/data/model/process_handle.dart';
import 'package:erp/res/colors.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ProcessTimeLineCard extends StatelessWidget {
  final int index;

  final ProcessHandle processHandle;

  final Map<int, String> empIdMap;
  final Map<int, String> orgIdMap;

  ProcessTimeLineCard({
    required this.index,
    required this.processHandle,
    this.empIdMap = const {},
    this.orgIdMap = const {},
  });

  get handleOrgName => orgIdMap[processHandle.handleOrgId] ?? "";

  get handleEmpName => empIdMap[processHandle.handleEmpId] ?? "";

  get indexStr => index.toString().padLeft(2, '0');

  get statusLabel {
    if (processHandle.handleStatus == 1) {
      return RichText(
        text: TextSpan(
          text: '已处理 - ',
          style: TextStyle(color: Colors.white, fontSize: 24.sp),
          children: [
            processHandle.handleResult == 'YES'
                ? TextSpan(text: '同意', style: TextStyle(color: Colors.white, fontSize: 24.sp))
                : TextSpan(text: '退回', style: TextStyle(color: Color(0xffFF4C4C), fontSize: 24.sp)),
          ],
        ),
      );
    } else {
      return Text('未处理', style: TextStyle(color: Color(0xffCCCCCC), fontSize: 24.sp));
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: AlignmentDirectional.centerStart,
      color: Colors.transparent,
      width: 636.w,
      height: 210.h,
      child: Stack(
        children: [
          Container(
            margin: EdgeInsets.only(top: 10.h, left: 10.w),
            width: 626.w,
            height: 200.h,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(10.r)),
              boxShadow: [
                BoxShadow(
                  offset: Offset(3.w, 5.w),
                  blurRadius: 15.r,
                  spreadRadius: 0,
                  color: Color.fromRGBO(38, 68, 128, 0.12),
                )
              ],
            ),
            child: Column(
              children: [
                Container(
                  height: 50.w,
                  decoration: BoxDecoration(
                    color: Color(0xff4C88FF),
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(10.r),
                      topRight: Radius.circular(10.r),
                    ),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Container(
                        child: Row(
                          children: [
                            SizedBox(width: 73.w),
                            Text(processHandle.nodeName, style: TextStyle(color: Colors.white, fontSize: 26.sp)),
                          ],
                        ),
                      ),
                      Container(
                        child: Row(
                          children: [
                            statusLabel,
                            SizedBox(width: 20.w),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
                Expanded(
                  child: Container(
                    padding: EdgeInsets.only(top: 30.h, left: 30.w),
                    child: Table(
                      // border: TableBorder.
                      columnWidths: {
                        0: FixedColumnWidth(250.w),
                        1: FlexColumnWidth(),
                      },
                      children: [
                        TableRow(
                          children: [
                            Text(
                              '部门：${handleOrgName}',
                              style: TextStyle(color: Color(0xff666666), fontSize: 24.sp),
                            ),
                            Text(
                              '日期：${processHandle.handleDate ?? ""}',
                              style: TextStyle(color: Color(0xff666666), fontSize: 24.sp),
                            ),
                          ],
                        ),
                        TableRow(
                          children: [
                            Padding(
                              padding: EdgeInsets.only(top: 30.h),
                              child: Text(
                                '人员：${handleEmpName}',
                                style: TextStyle(color: Color(0xff666666), fontSize: 24.sp),
                              ),
                            ),
                            Padding(
                              padding: EdgeInsets.only(top: 30.h),
                              child: Tooltip(
                                message: '${processHandle.handleContent ?? ""}',
                                child: Text(
                                  '处理意见：${processHandle.handleContent ?? ""}',
                                  style: TextStyle(color: Color(0xff666666), fontSize: 24.sp),
                                  overflow: TextOverflow.ellipsis,
                                ),
                              ),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                )
              ],
            ),
          ),
          Positioned(
            top: 0,
            left: 0,
            child: Container(
              alignment: AlignmentDirectional.center,
              width: 60.w,
              height: 60.w,
              decoration: BoxDecoration(
                color: Colours.white,
                shape: BoxShape.circle,
                border: Border.all(width: 0, style: BorderStyle.none),
                boxShadow: [
                  BoxShadow(
                    offset: Offset(-3.w, -5.w),
                    blurRadius: 10.r,
                    spreadRadius: 0,
                    color: Color.fromRGBO(38, 68, 128, 0.12),
                  ),
                ],
              ),
              child: Text(
                indexStr,
                style: TextStyle(
                  fontFamily: 'ShiShangZhongHeiJianTi',
                  fontSize: 30.sp,
                  color: Color(0xff4C88FF),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
